﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYView;

namespace Model
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	internal class CmdCableTrayCode : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Autodesk.Revit.DB.View activeView = commandData.Application.ActiveUIDocument.Document.ActiveView;
			if ((int)activeView.ViewType != 1 && (int)activeView.ViewType != 2 && (int)activeView.ViewType != 3 && (int)activeView.ViewType != 117 && (int)activeView.ViewType != 4)
			{
				Result result = SwitchView.SetUsableView((CmdViewType)115, commandData);
				if (result != Result.Succeeded)
				{
					return result;
				}
			}
			if (new CableTrayCode(commandData).Excute())
			{
				return Autodesk.Revit.UI.Result.Succeeded;
			}
			return Autodesk.Revit.UI.Result.Failed;
		}
	}
}
